Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@swc-node/core
Advanced tools
@swc-node/core is a Node.js binding for the SWC (Speedy Web Compiler) project, which is a super-fast TypeScript/JavaScript compiler written in Rust. It allows you to transform and compile TypeScript and JavaScript code with high performance.
Transforming Code
This feature allows you to transform TypeScript or JavaScript code into JavaScript. The `transformSync` function takes the source code and an options object, and returns the transformed code.
const { transformSync } = require('@swc-node/core');
const output = transformSync('const x: number = 1;', { jsc: { parser: { syntax: 'typescript' } } });
console.log(output.code);
Compiling Code
This feature allows you to compile TypeScript or JavaScript code asynchronously. The `compile` function takes the source code and an options object, and returns a promise that resolves to the compiled code.
const { compile } = require('@swc-node/core');
compile('const x: number = 1;', { jsc: { parser: { syntax: 'typescript' } } }).then(output => {
console.log(output.code);
});
Using with Node.js
This feature allows you to use SWC with Node.js directly. By requiring `@swc-node/register`, you can run TypeScript code in Node.js without pre-compiling it.
require('@swc-node/register');
const x: number = 1;
console.log(x);
TypeScript is a language for application-scale JavaScript. It includes a compiler that can compile TypeScript code to JavaScript. Compared to @swc-node/core, TypeScript's compiler is slower but offers more comprehensive type-checking and language features.
Babel is a JavaScript compiler that allows you to use next-generation JavaScript, today. It can transform syntax, polyfill features that are missing in your target environment, and more. Babel is more feature-rich but slower compared to @swc-node/core.
esbuild is an extremely fast JavaScript bundler and minifier. It supports TypeScript and modern JavaScript syntax out of the box. esbuild is comparable to @swc-node/core in terms of speed but focuses more on bundling and minification.
@swc-node/core
transform AjaxObservable.ts to ES2015 & CommonJS
JavaScript
.
@swc-node/core x 151 ops/sec ±3.74% (77 runs sampled)
@swc/core x 107 ops/sec ±0.51% (78 runs sampled)
esbuild x 52.89 ops/sec ±1.58% (67 runs sampled)
typescript x 21.08 ops/sec ±9.68% (40 runs sampled)
Transform rxjs/AjaxObservable.ts benchmark bench suite: Fastest is @swc-node/core
export interface Options {
target?: 'es3' | 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020'
module?: 'commonjs' | 'umd' | 'amd' | 'es6'
sourcemap?: boolean | 'inline'
experimentalDecorators?: boolean
emitDecoratorMetadata?: boolean
dynamicImport?: boolean
}
export function transformSync(
source: string | Buffer,
path: string,
options?: Options,
): {
code: string
map: string
}
export function transform(
source: string | Buffer,
path: string,
options?: Options,
): Promise<{
code: string
map: string
}>
FAQs
Faster swc nodejs binding
The npm package @swc-node/core receives a total of 629,367 weekly downloads. As such, @swc-node/core popularity was classified as popular.
We found that @swc-node/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.